package com.block.test.factory;

import com.block.common.util.ApplicationContextUtil;
import com.block.test.service.IValidateService;
import com.block.test.service.impl.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 请求参数校验工厂(网关)
 */
public class ReqValidateFactory {
    private static Map<String, Class<? extends IValidateService>> validataMap = new HashMap<>(30);

    static {
        validataMap.put("/api/sms/sendSmsCode", SendSmsCodeValidateService.class);
        validataMap.put("/api/member/updateInfo", UpdateInfoValidateService.class);
    }

    /**
     * 根据uri获取实现类
     *
     * @param uri
     * @return
     */
    public static IValidateService getValidateService(String uri) {
        Class<? extends IValidateService> validataService = validataMap.get(uri);
        if (validataService != null) {
            return ApplicationContextUtil.getBean(validataService);
        }
        return null;
    }
}
